﻿Public Class frmProject

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        '在增加方案前应至少输入一个污染源
        If AermodProject0.Aermod.Source.GetAllSourceCount <= 0 Then
            MessageBox.Show("在添加方案前请至少输入一个污染源!")
            Exit Sub
        End If

        Dim frmP As New CAermod.frmPorjSet
        frmP.AllPolluts = AermodProject0.Aermod.Control.AllPolluts.Clone
        frmP.Source = AermodProject0.Aermod.Source.Clone

        ''''''''''''''''''''''''''''''''''''''
        '新增加的方案的代码
        '''''''''''''''''''''''''''''''''''''
        frmP.ProjSet.InitalReceptorSelected(AermodProject0.Aermod.Receptor)
        frmP.ProjSet.ProjName = "方案" & AermodProject0.ProjSetCollection.Index + 1
        If frmP.ShowDialog = Windows.Forms.DialogResult.OK Then
            Dim PSet As New CAermod.ProjSet
            PSet = frmP.ProjSet.Clone
            PSet.ID = "Proj_" & AermodProject0.ProjSetCollection.Index + 1
            AermodProject0.ProjSetCollection.Add(PSet)
            TreeViewProject.Nodes.Add(frmP.ProjSet.ProjName)
            TreeViewProject.Nodes(TreeViewProject.Nodes.Count - 1).Checked = True
            AermodProject0.ProjSetCollection.Index += 1

        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If Me.TreeViewProject.SelectedNode Is Nothing Then
            Exit Sub
        End If
        Dim iSelcted As Integer = Me.TreeViewProject.SelectedNode.Index
        If iSelcted >= 0 Then
            '如果删除项目的方案时，还需要删除对应的计算结果的文件夹！
            Try
                Dim PrjPath As String = My.Computer.FileSystem.GetFileInfo(AermodProject0.SaveName).DirectoryName
                Dim strNameLast As String = CAermod.GetFileName(AermodProject0.SaveName)
                Dim strTempName As String = PrjPath & "\" & strNameLast & "\" & "Aermod\" & AermodProject0.ProjSetCollection.Item(iSelcted).ID
                My.Computer.FileSystem.DeleteDirectory(strTempName, FileIO.DeleteDirectoryOption.DeleteAllContents)
            Catch ex As Exception

            End Try
            AermodProject0.ProjSetCollection.Remove(iSelcted)
            Me.TreeViewProject.Nodes.RemoveAt(iSelcted)
            If Me.TreeViewProject.Nodes.Count > 0 Then
                'Me.TreeViewProject.Nodes(iSelcted - 1) = True
                'If Me.chkProject.SelectedIndex < 0 Then
                '    Me.chkProject.SelectedIndex = 0
                'End If
            End If
        End If
    End Sub
    Public Sub RefreshProject()
        Me.TreeViewProject.Nodes.Clear()
        For i As Integer = 0 To AermodProject0.ProjSetCollection.Count - 1
            Me.TreeViewProject.Nodes.Add(AermodProject0.ProjSetCollection.Item(i).ProjName)
            TreeViewProject.Nodes(i).Checked = AermodProject0.ProjSetCollection.Item(i).Selected
        Next
    End Sub

    Private Sub 网格点的各点高值1_GridValueChanaged()
        MessageBox.Show("")
    End Sub

    Private Sub 网格点的各点高值1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub 查看结果ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 查看结果ToolStripMenuItem.Click
        'Dim frmR As New AermodAnalyse.frmAnlyze
        'Dim i As Integer = Me.chkProject.SelectedIndex
        'If i >= 0 Then
        '    frmR.frmAnlizeResult_0.CtrlResult1.ProjResult = AermodProject0.ProjSetCollection.Item(i).ProjResult
        '    Dim PrjPath As String = My.Computer.FileSystem.GetFileInfo(AermodProject0.SaveName).DirectoryName
        '    Dim strNameLast As String = CAermod.GetFileName(AermodProject0.SaveName)
        '    frmR.frmAnlizeResult_0.CtrlResult1.ProjSavePath = PrjPath & "\" & strNameLast & "_Result\" & AermodProject0.ProjSetCollection.Item(i).ProjSet.ProjName & "\"
        '    frmR.ShowDialog()
        'End If

    End Sub

    Private Sub ContextMenuStrip1_Opening(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles ContextMenuStrip1.Opening

    End Sub

    Private Sub TreeViewProject_AfterCheck(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeViewProject.AfterCheck
        If AermodProject0.ProjSetCollection.Count = Me.TreeViewProject.Nodes.Count Then
            For i As Integer = 0 To AermodProject0.ProjSetCollection.Count - 1
                AermodProject0.ProjSetCollection.Item(i).Selected = Me.TreeViewProject.Nodes.Item(i).Checked
            Next
        End If
    End Sub

    Private Sub TreeViewProject_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeViewProject.AfterSelect

    End Sub

    Private Sub TreeViewProject_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles TreeViewProject.DoubleClick
        Dim iSelcted As Integer = Me.TreeViewProject.SelectedNode.Index
        If iSelcted >= 0 Then
            Dim frmP As New CAermod.frmPorjSet
            frmP.AllPolluts = AermodProject0.Aermod.Control.AllPolluts.Clone
            frmP.Source = AermodProject0.Aermod.Source.Clone
            frmP.ProjSet = AermodProject0.ProjSetCollection.Item(iSelcted).Clone
            If frmP.ShowDialog = Windows.Forms.DialogResult.OK Then
                AermodProject0.ProjSetCollection.Item(iSelcted) = frmP.ProjSet.Clone
                RefreshProject()
            End If
        End If
    End Sub

    Private Sub TreeViewProject_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles TreeViewProject.Validating

    End Sub
End Class
